<?php
/**
 * Created by PhpStorm.
 * User: Frings
 * Date: 2017-10-22
 * Time: 12:41
 */

namespace app\models;

use app\librarys\DbCacheUtility;

class Report
{
    public static function getPlatformRakeFeeCount()
    {
        $cmd = \Yii::$app->db->createCommand('SELECT count(1) FROM t_platform_rake_fee t1 
                                                  INNER JOIN t_ad t2 ON t2.id = t1.ad_id
                                                  INNER JOIN t_merchant t3 ON t3.id = t2.merchant_id');
        $count = DbCacheUtility::queryScalar($cmd);
        return $count;
    }

    public static function getPlatformRakeFeeList($page, $pageSize)
    {
        $cmd = \Yii::$app->db->createCommand('SELECT t1.*,t2.title,t3.name AS merchant_name FROM t_platform_rake_fee t1 
                                                  INNER JOIN t_ad t2 ON t2.id = t1.ad_id
                                                  INNER JOIN t_merchant t3 ON t3.id = t2.merchant_id
                                              ORDER BY t1.create_datetime DESC limit :offset , :limit');
        $cmd->bindValue(':offset', $page * $pageSize);
        $cmd->bindValue(':limit', $pageSize);
        $items = DbCacheUtility::queryAll($cmd);
        return $items;
    }


    public static function getAgentRakeFeeCount()
    {
        $cmd = \Yii::$app->db->createCommand('SELECT count(1) FROM t_agent_rake_fee t1
                                                  INNER JOIN t_ad t2 ON t2.id = t1.ad_id
                                                  INNER JOIN t_merchant t3 ON t3.id = t2.merchant_id
                                                  INNER JOIN t_agent t4 ON  t4.id = t1.agent_id
');
        $count = DbCacheUtility::queryScalar($cmd);
        return $count;
    }

    public static function getAgentRakeFeeList($page, $pageSize)
    {
        $cmd = \Yii::$app->db->createCommand('SELECT t1.*,t2.title,t3.name AS merchant_name,t4.agent_name FROM t_agent_rake_fee t1
                                                  INNER JOIN t_ad t2 ON t2.id = t1.ad_id
                                                  INNER JOIN t_merchant t3 ON t3.id = t2.merchant_id
                                                  INNER JOIN t_agent t4 ON  t4.id = t1.agent_id

                                              ORDER BY t1.create_datetime DESC limit :offset , :limit');
        $cmd->bindValue(':offset', $page * $pageSize);
        $cmd->bindValue(':limit', $pageSize);
        $items = DbCacheUtility::queryAll($cmd);
        return $items;
    }
}